package no.ntnu.fp.gui.listeners;

import java.io.IOException;
import java.net.ConnectException;

import no.ntnu.fp.client.exceptions.NetworkException;
import no.ntnu.fp.gui.events.LogoutRequestedEvent;
import no.ntnu.fp.messages.impl.LogoutMessage;
import no.ntnu.fp.net.co.Connection;

public class LogoutListener implements GuiListener<LogoutRequestedEvent> {
	private final Connection connection;
	
	public LogoutListener(Connection connection){
		this.connection = connection;
	}

	@Override
	public void handleEvent(LogoutRequestedEvent evt) {
		try {
			connection.send(new LogoutMessage(evt.getEmployee()).toString());
		} catch (ConnectException e) {
			System.err.println("Exception in LogoutListener\n" + e);
		} catch (IOException e) {
			throw new NetworkException("Unable to send message to server", e);
		}
	}

	@Override
	public boolean isLongRunningListener() {
		// TODO Auto-generated method stub
		return false;
	}

}
